﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

using ESOL.Common.Entity;
using ESOL.Business.Bpt;
using ESOL.Common;

namespace ESOL.WinUI.Bpt
{
    public partial class frmMaintainBlueprintDetail : BaseForm.frmBaseDialogyQueryForm
    {
        #region Variable
        public BptDrawBlueprintEntity SelectDrawBlue { get; set; }
        #endregion

        #region Constructor
        public frmMaintainBlueprintDetail()
        {
            InitializeComponent();
        }
        #endregion

        #region Functions
        private void BindGrid()
        {
            if (SelectDrawBlue == null)
            {
                MessageBox.Show("载入失败，请重新选择。");
                return;
            }
            DataTable dt = new DataTable();
            dt = BptBlueprintBs.GetDrowProductByPrintID(SelectDrawBlue.BlueprintId);
            if (dt != null)
            {
                gvMain.DataSource = dt;
            }
        }

        private void ShowPictures(string ProductCode)
        {
            EsolWevServices.EsolService EService = new EsolWevServices.EsolService();
            byte[] bytes=EService.DownloadFile(ProductCode+".jpg");
            if (bytes != null)
            {
                Image img = CommonFunctions.byteArrayToImage(bytes);
                string ssrt = "C:" + @"\" + "TempPictures" +@"\"+ ProductCode + ".jpg";
                img.Save(ssrt);
                //System.Diagnostics.Process.Start("rundll32.exe shimgvw.dll,ImageView_Fullscreen" + ssrt);
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                string fileName = ssrt;
                process.StartInfo.FileName = fileName;
                process.StartInfo.Arguments = "rundll32.exe C:\\WINDOWS\\system32\\shimgvw.dll,ImageView_Fullscreen";
                process.StartInfo.UseShellExecute = true;
                process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                process.Start();
                process.Close();
            }
            else
            {
                MessageBox.Show("没有与其对应的图片，请先上传图纸后查看。");
            }
        }
        #endregion

        #region Event
        protected override void OnShown(EventArgs e)
        {
            try
            {
                Directory.Delete("C:" + @"\" + "TempPictures", true);
            }
            catch
            { }
            Directory.CreateDirectory("C:" + @"\" + "TempPictures");
            BindGrid();
            base.OnShown(e);
        }

        protected override void Click_Confirm()
        {
            try
            {
                Directory.Delete("C:" + @"\" + "TempPictures", true);
            }
            catch
            { }
            base.Click_Confirm();
        }

        protected override void Click_Cancel()
        {
            try
            {
                Directory.Delete("C:" + @"\" + "TempPictures", true);
            }
            catch
            { }
            base.Click_Cancel();
        }

        private string sProductCodeSelected;
        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            DataRow dr=gridView1.GetDataRow(e.RowHandle);
            sProductCodeSelected = dr["PRODUCT_CODE"].ToString();
        }
        #endregion

    }
}
